package com.atguigu.userprofile.dao

import com.atguigu.userprofile.bean.TagInfo
import com.atguigu.userprofile.util.MySqlUtil

/**
 * @Author: cpw
 * @Date: 2021/8/1 16:56
 * @Version 1.0
 */
object TagInfoDao {
    def getTagInfoByTask(taskId:String):TagInfo ={
        var tagInfo: TagInfo = null
        val tagInfoSql =
            s"""
               | select * from tag_info where tag_task_id = $taskId
               |""".stripMargin
        val maybeTagInfo: Option[TagInfo] = MySqlUtil.queryOne(tagInfoSql, classOf[TagInfo], true)
        if(maybeTagInfo == None){
            throw new RuntimeException("no tag by task_id:" + taskId)
        }else{
            tagInfo = maybeTagInfo.get
        }
        tagInfo
    }

    def getTagListWithOn():List[TagInfo]={
        val selectTagList =
            """
              |  select tg.id,tag_code,tag_name,parent_tag_id,tag_type,
              |  tag_value_type,tag_value_limit,tag_task_id,tag_comment,tg.create_time
              |  from tag_info tg join task_info tk on tg.tag_task_id = tk.id
              |  where tk.task_status = '1'
              |""".stripMargin

        val tagInfoList: List[TagInfo] = MySqlUtil.queryList(selectTagList, classOf[TagInfo], true)

        tagInfoList
    }


}
